package com.haiqi.modules.map.web;

import com.github.pagehelper.PageInfo;
import com.haiqi.common.BaseController;
import com.haiqi.common.annotation.SafeAuthority;
import com.haiqi.common.bean.DataGridBean;
import com.haiqi.common.bean.PageBean;
import com.haiqi.common.persistence.entity.NavigatWarning;
import com.haiqi.common.utils.HttpRequestUtils;
import com.haiqi.common.utils.PageUtils;
import com.haiqi.modules.map.service.NavigatWarningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by hythzx on 2016/6/28.
 */

@RequestMapping("/manage/map/navigat/warning")
@Controller
@SafeAuthority(menuCode = "monitorLocation,companyMonitorLocation")
public class NavigatWarningController extends BaseController {

    @Autowired
    private NavigatWarningService navigatWarningService;

    @Value("${geo.server}")
    private String geoServer;

    @RequestMapping("/save")
    @ResponseBody
    public Map save(NavigatWarning navigatWarning,String wkt){
        System.out.println(wkt);
        navigatWarning.setCoordinates(wkt);
        boolean success = navigatWarningService.save(navigatWarning);
        Map map = new HashMap();
        map.put("result",success);
        map.put("guid",navigatWarning.getGuid());
        return map;
    }

    @ResponseBody
    @RequestMapping("/delete")
    public Map delete(NavigatWarning navigatWarning){
        boolean  success = navigatWarningService.delete(navigatWarning);
        Map map = new HashMap();
        map.put("result",success);
        return map;
    }

    @ResponseBody
    @RequestMapping("/ajax/data/list")
    public List<NavigatWarning> getDataList(NavigatWarning navigatWarning){
        List<NavigatWarning> dataList = navigatWarningService.getDataList(navigatWarning);
        return dataList;
    }

    @ResponseBody
    @RequestMapping("/ajax/data/page/list")
    public DataGridBean<NavigatWarning> getPageDataList(NavigatWarning navigatWarning, PageBean page){
        PageUtils.generatePage(page);
        List<NavigatWarning> dataList = navigatWarningService.getDataList(navigatWarning);
        PageInfo<NavigatWarning> pageInfo = new PageInfo<>(dataList);
        DataGridBean<NavigatWarning> mobileShipDataGridBean = new DataGridBean<>();
        PageUtils.convertToEasyuiList(pageInfo, mobileShipDataGridBean);
        return mobileShipDataGridBean;
    }

    @ResponseBody
    @RequestMapping("/gf")
    public String gf(Map map, HttpServletRequest request){
        Map<String, String[]> parameterMap = request.getParameterMap();
        String s = HttpRequestUtils.sendPost(geoServer, parameterMap);
        return s;
    }

    @ResponseBody
    @RequestMapping("/getFeatureByBbox")
    public String getFeatureByBbox(String bbox,String ft){
        String xml = HttpRequestUtils.GetXML(bbox.split(","), ft.split(","));
        String s = HttpRequestUtils.postXml(geoServer, xml);
        return s;
    }

//    @ResponseBody
//    @RequestMapping("/saveserver")
//    public Map saveserver(ShipServer shipServer,String wkt) {
//        shipServer.setCoordinates(wkt);
//        boolean success = navigatWarningService.saveserver(shipServer);
//        Map map = new HashMap();
//        map.put("result",success);
//        map.put("guid",shipServer.getGuid());
//        return map;
//    }
}
